#include "queueC.h"
void regularize(QueueC *q) {
  while (q->head > CAPACITY && q->tail > CAPACITY) {
    q->head -= CAPACITY;
    q->tail -= CAPACITY;
  }
}
void initC(QueueC *q) { q->head = q->tail = -1; }

bool isFullC(QueueC *q) { return q->tail - q->head == CAPACITY; }

bool isEmptyC(QueueC *q) { return q->tail - q->head == 0; }

bool enqueueC(QueueC *q, int x) {
  if (isFullC(q))
    return false;
  q->data[(++q->head) % CAPACITY] = x;
  regularize(q);
  return true;
}

bool dequeueC(QueueC *q, int *x) {
  if (isEmptyC(q))
    return false;
  *x = q->data[(++q->tail) % CAPACITY];
  regularize(q);
  return true;
}
void show(QueueC *q) {
#include "stdio.h"
  printf("QueueC: ");
  for (int i = q->tail; i < q->head; i++)
    printf("%d ", q->data[i % CAPACITY]);

  printf("\n");
}